package com.bms.api.bussiness.dict.web;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bms.common.base.common.bean.Result;
import com.bms.common.base.web.BaseController;
import com.bms.common.bussiness.dict.entity.Dict;
import com.bms.common.bussiness.dict.service.IDictService;
import com.feilong.core.Validator;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 赛事表 前端控制器
 * </p>
 *
 * @author xj
 * @since 2018-08-15
 */
@RestController
@RequestMapping("dict")
@Api(value="Dict-Api",tags="数据字典接口")
public class DictController extends BaseController{

	@Autowired
	private IDictService dictService;
	
	@PostMapping("list")
	@ApiOperation(value = "数据字典列表")
	public Result list(@RequestParam(required = false) String code){
		EntityWrapper<Dict> wrapper = new EntityWrapper<>();
		if (Validator.isNotNullOrEmpty(code)) {
			wrapper.eq("code", code);
		}
		List<Dict> dictList = dictService.selectList(wrapper.eq("pid", 0).orderBy("id", true));
		for (Dict dict : dictList) {
			dict.setDicts(dictService
					.selectList(Condition.create().eq("pid", dict.getId()).orderBy("id", true)));
		}
		return json(dictList);
	}
	
}

